package com.sumbo.streams;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.kafka.common.serialization.Deserializer;

import java.util.Map;

/**
 * \* User: MeiZhongHao
 * \* Date: 2019-05-31
 * \* Time: 14:29
 * \* Description:
 * \
 */
public class StatisticsDeserializer implements Deserializer<Statistics> {

    private static final ObjectMapper jsonMapper = new ObjectMapper();

    @Override
    public void configure(Map<String, ?> map, boolean b) {

    }

    @Override
    public Statistics deserialize(String s, byte[] bytes) {
        if (bytes == null) {
            return null;
        } else {
            try {
                return jsonMapper.readValue(bytes, Statistics.class);
            } catch (Exception ex) {
                return null;
            }
        }
    }

    @Override
    public void close() {

    }
}